using System;
using System.Collections;

using System.Xml.Serialization;

namespace Evaluant.Uss.MappingGenerator.TypeConverter
{
	[Serializable]
	public class DataTypeCollection : CollectionBase
	{

		public int Add(DataType value)
		{
			return base.List.Add(value as object);
		}

		public void Remove(DataType value)
		{
			base.List.Remove( (object)value);
		}

		public void Insert(int index, DataType value)
		{
			base.List.Insert(index, (object)value);
		}

		public bool Contains(DataType value)
		{
			return base.List.Contains( (object)value);
		}

		public DataType this[int index]
		{
			get { return ( (DataType)base.List[index]); }
		}

		public DataType GetDataType(Type type)
		{

#if !EUSS11
            if (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
            {
                type = type.GetGenericArguments()[0];
            }
#endif

			foreach(DataType d in base.List)
				if(d.Type == type.FullName)
					return d;

            DataType dt = new DataType();
            dt.DbType = System.Data.DbType.Object;
            dt.Type = typeof(object).FullName;

            return dt;
		}
	}
}
